Do not derive Clone/Copy/Eq*/Ord* for opaque types#1667
Do not derive Clone/Copy/Eq*/Ord* for opaque types#1667elichai wants to merge 2 commits intorust-lang:masterfrom
Conversation
emilio
left a comment
There was a problem hiding this comment.
Observables look good, but the place to check it is not quite right.
| @@ -14,16 +14,12 @@ pub fn gen_partialeq_impl( | |||
| ) -> Option<proc_macro2::TokenStream> { | |||
| let mut tokens = vec![]; | |||
There was a problem hiding this comment.
You should just debug_assert!(!item.is_opaque(..)) if we decide not to derive partialeq for these, then remove the conditional below.
| impl CanDeriveHash for Item { | ||
| fn can_derive_hash(&self, ctx: &BindgenContext) -> bool { | ||
| self.id().can_derive_hash(ctx) | ||
| self.id().can_derive_hash(ctx) && !self.is_opaque(ctx, &()) |
There was a problem hiding this comment.
Instead of this, the right place for this is returning CanDerive::No here:
rust-bindgen/src/ir/analysis/derive.rs
Line 158 in ec85170
There was a problem hiding this comment.
Yeah. I started there an then thought that maybe I should "attack" this at the source to make sure i'm not missing other places.
I'll change.
There was a problem hiding this comment.
One problem is that this also affects Default and Debug
And for some reason also affected stuff the current code missed like
There was a problem hiding this comment.
Well, sure that'd affect more traits, you can choose what it affects conditionally adding something like self.derive_trait.can_derive_opaque().
242bbcd to
5d4e52d
Compare
|
Sorry, I hadn't noticed this was updated (GitHub likes not to notify for force-pushes looks like). It seems like tests/opaque_pointer.rs doesn't build and CI is red because of that, because we still derive copy on the struct around the opaque thing. |
|
Yeah, I'm not really sure what's the right way forward or if this PR is even a wanted feature (it is a breaking change). I'll play with it a bit more to see if I can get the "right way" to still derive |
|
Well, we should clearly not be deriving |
5d4e52d to
e63dbd8
Compare
|
I changed the implementation, but I still don't get why it doesn't implement Debug manually (with the |
|
Ops, I should fix both the rustfmt and the big array problem. Edit: I just missed the fact that it's a different trait :), it's still running multiple times by for my isolated test it always ends up with Debug -> Manually: So the The problem seem to be |
|
Found the problem :) @emilio what do you think I should do? do you even agree that it makes more sense to print something like |
e63dbd8 to
186501b
Compare
I'd be ok with that I think... Either way, really. |
|
Hi, sorry I left this as is, context switching is hard. I think this comment tries to explain that but I don't quite understand: https://github.com/rust-lang/rust-bindgen/pull/1667/files#diff-ab2ef507baf5b00651f924fb3cb4241cR51 |
|
So regarding unions, I think emitting an opaque struct for opaque unions is better, and should save a bit of code. But I still need to take a closer look here. |
|
☔ The latest upstream changes (presumably 0e25962) made this pull request unmergeable. Please resolve the merge conflicts. |
Hi,
This is an attempt to solve #1656
I'm not sure if the
IsOpaquetrait is defined only on actually opaque types. but I used that to check and not impl anything except Debug/Default